# -*- coding: utf-8 -*-
# @Time    : 2021/5/6 9:46
# @Author  : yejing
# @Email   : 458663810@qq.com
# @File    : 04.ATM取款机.py
# @Software: PyCharm


# 1、分析atm存取款功能
# 两个类：ATM 用户
# ATM:
#  钱 ，名称，位置 ，
# 方法：放钱进去，取出atm里面的钱

# 用户类:
# 属性：账户，密码，账户金额
# 方法:存钱，取钱，查看金额


# class Atm():
#     money = 50000
#     def get_money(self,getmoney):
#         if getmoney <= self.money:
#             self.money -= getmoney
#             print(f"取了{getmoney}元钱")
#         else:
#             print("ATM余额不足")
#     def give_money(self,givemoney):
#         self.money += givemoney
#
# class user():
#     def __init__(self,getmoney,addmoney):
#         self.getmoney = getmoney
#         self.addmoney = addmoney
#         self.money = 0
#     def getmoney(self,getmoney):
#         if getmoney <= self.money:
#             print(f"取了{getmoney}元钱")
#         else:
#             print("余额不足")
#     def addmoney(self,addmoney):
#         self.money += addmoney

class ATM():
    def __init__(self,money,name,location):
        self.money = money
        self.name = name
        self.location = location

    def add_money(self,money):
        print(f"存入金额:{money}")
        self.money += money

    def take_money(self,money):
        print(f"取出金额:{money}")
        self.money -= money

class User():
    def __init__(self,name,passwd,money):
        self.name = name
        self.passwd = passwd
        self.money = money
    def save_money(self,money,atmobj):
        print(f"存入金额{money}")
        self.money += money
        atmobj.money += money
    def get_money(self,money,atmobj):
        print(f"取出金额{money}")
        if self.money >= money and atmobj.money >= money:
            self.money -= money
            atmobj.money -= money
        else:
            print("账户或取款机余额不足")
    def show_money(self):
        print(f"当前账户余额为{self.money}")

print("欢迎来到三乐ATM取款机".center(30,"="))

atm1 = ATM(10000,"工商银行","农大")
atm2 = ATM(20000,"建设银行","工大")
user1 = User("yejing","123456",50000)
user2 = User("xiayuzhen","xiayuzhen",50000)

while True:
    print("""
    按1查看账户余额
    按2进行取款操作
    按3进行存款操作
    按q退出系统
    """)

    num = input("请输入您的选项：")
    if num == "1":
        print(f"您的账户余额为{user1.money}")
        print("-" * 30)
    if num == "2":
        take_mon = int(input("请输入您需要取款的金额："))
        user1.get_money(take_mon, atm1)
        print(f"您的账户余额为{user1.money}")
        print("-" * 30)

    if num == "3":
        save_mon = int(input("请输入您需要存款的金额："))
        user1.save_money(save_mon, atm1)
        print(f"您的账户余额为{user1.money}")
        print("-" * 30)

    if num == "q":
        print("系统退出成功...")
        break






